package com.spe.common.mybatis.generator;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author limingliang
 * @date 2020/12/11 17:52
 */
@Data
@Accessors(chain = true)
public class CodeProperties {

    /**
     * 父工程路径
     */
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private final String projectPath = System.getProperty("user.dir");

    /**
     * 默认开发人员
     */
    private String author = System.getenv("USERNAME");

    /**
     * 默认包路径
     */
    private String parent = "com.spe";

    /**
     * 项目模块名
     */
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private List<String> projectModules = new ArrayList<>(3);

    /**
     * 数据库连接配置
     */
    private String driverClassName = "com.mysql.cj.jdbc.Driver";
    private String url = "jdbc:mysql://localhost:3306/green?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT";
    private String username = "root";
    private String password = "12345678";

    /**
     * 设置项模块 上下级方式
     *
     * @param projectModule
     * @return
     */
    public CodeProperties setProjectModule(String projectModule) {
        this.projectModules.add(projectModule);
        return this;
    }

    /**
     * 获取项目模块路径
     *
     * @return
     */
    public String getProjectModulePath() {
        return projectPath + getProjectModuleDir();
    }

    /**
     * 获取项目模块拼接后目录
     *
     * @return
     */
    private String getProjectModuleDir() {
        StringBuffer sb = new StringBuffer();
        projectModules.forEach(projectModule -> {
            sb.append(File.separator).append(projectModule);
        });
        return sb.toString();
    }

}
